package states;
import gui.OpCom;
import regulators.BallAndBeamRegul;
import regulators.BeamRegul;
import se.lth.control.realtime.DigitalIn;
import se.lth.control.realtime.DigitalOut;
import stateMachine.StateMachine;
import stateMachine.StateMachine.Ball;
import monitor.StateVariableMonitor;

public class TrackSize extends StateClass implements State {



	public TrackSize(DigitalIn initialPosSensor, DigitalOut digitalSolenoid, BeamRegul beam,
			BallAndBeamRegul ballAndBeam, OpCom op,StateVariableMonitor stateVariableMonitor) {
		super(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor);

	}

	@Override
	public void initialExcecution() {
		op.displayStep("Track Size");
		ballAndBeam.BallTrack(true);
	}

	@Override
	public void excecute() {

	}

	@Override
	public boolean stateOfExcecution() {
		return ballAndBeam.getBallSize() == null? false:true;
	}



	@Override
	public void nextState() {
		Ball ball = ballAndBeam.getBallSize();
		switch (ball) {
		case LARGE: setCurrentState(new Drop(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor));
		op.displayWeight("LARGE BALL");
		break;
		case MEDIUM: setCurrentState(new Throw(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor));
		op.displayWeight("MEDIUM BALL");
		break;
		case SMALL: setCurrentState(new PlaceBall(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor));
		op.displayWeight("SMALL BALL");
		break;
		case UNKNOWNBALL: setCurrentState(new TrackSize(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor));
		default: setCurrentState(new TrackSize(initialPosSensor, digitalSolenoid, beam, ballAndBeam, op, stateVariableMonitor));
		op.writeToConsole("Something went wrong!!!");
		op.displayWeight("UNKNOWN");
		break;

		}
	}

	@Override
	public void suspend() {
		ballAndBeam.shutDown();
	}

	@Override
	public void resume() {
		ballAndBeam.restart();
		this.initialExcecution();
	}
}